package com.ys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ys.constant.ShopCode;
import com.ys.exception.CastException;
import com.ys.mapper.CouponMapper;
import com.ys.pojo.TradeCoupon;
import com.ys.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class CouponServiceImpl extends ServiceImpl<CouponMapper, TradeCoupon> implements CouponService{
    @Autowired
    private CouponMapper couponMapper;
    public TradeCoupon findCouponById(Long couponId){
        System.out.println(couponId);
        return couponMapper.selectById(couponId);
    }

    @Override
    public Boolean changeCoponStatus(TradeCoupon coupon) {
        try {
            //判断请求参数是否合法
            if (coupon == null || StringUtils.isEmpty(coupon.getCouponId())) {
                CastException.cast(ShopCode.SHOP_REQUEST_PARAMETER_VALID);
            }
            //更新优惠券状态为已使用
            couponMapper.updateById(coupon);

            return ShopCode.SHOP_SUCCESS.getSuccess();

        }catch (Exception e) {

            return ShopCode.SHOP_FAIL.getSuccess();
        }
    }
}
